global data_folder "W:\intimate\data"
global log_folder "W:\intimate\dofiles\logs"
global result_folder "W:\intimate\results_revision"
 
use "$data_folder\aizer_munic_ed_oo_bartik_iv", clear
keep if year>=2006 
merge 1:1 year educ seutukunta16 using "W:\intimate\data\cross_dv_aizer.dta"
drop if _merge ==2 
drop _merge 

merge 1:1 year educ seutukunta16 using "$data_folder\control_var"
drop if _merge ==2 
drop _merge

drop if female_emp==0
drop if male_emp==0 

merge m:1 year seutukunta16 using "$data_folder\aizer_violent_crime_region"
drop if _merge ==2 
drop _merge

merge m:1 year seutukunta16 educ using "$data_folder\aizer_violent_crime_region_ed"
drop if _merge ==2 
drop _merge

gen log_dv=log(dv)

destring seutukunta16, replace 

* time trends 
tab seutukunta16, gen (region)

forvalues i=1/70{
   gen year_region`i'=year*region`i'
}

sort seutukunta16 educ year 
bysort seutukunta16 educ: gen log_dv_lag=log_dv[_n-1]


* look at man and women's outside options separately 
gen log_wage_op_f=log(wage_op_f)
gen log_wage_op_m=log(wage_op_m)

gen oo_emp=0 
append using "$data_folder\oo_emp_dv"


sum dv0, d
scalar define ymsample=r(mean)
scalar define ysdsample=r(sd)

// incoporate Aizer paper's coefficient to produce the coefplot
matrix replic=J(2,3,.)

matrix ser=J(2,3,.)


matrix replic[1,1]=-0.781
matrix replic[2,1]=0.956

matrix ser[1,1]=-0.559
matrix ser[2,1]=0.516


reg log_dv log_wage_op_f log_wage_op_m i.year i.educ i.seutukunta16 year_region* if oo_emp==0, cluster(seutukunta16)

matrix replic[1,2]=_b[log_wage_op_f]
matrix replic[2,2]=_b[log_wage_op_m]

matrix ser[1,2]=_se[log_wage_op_f]
matrix ser[2,2]=_se[log_wage_op_m]

reg log_dv women_oo men_oo i.year i.educ i.seutukunta16 year_region* if oo_emp==1, cluster(seutukunta16)


matrix replic[1,3]=_b[women_oo]
matrix replic[2,3]=_b[men_oo]
matrix ser[1,3]=_se[women_oo]
matrix ser[2,3]=_se[men_oo]

matrix list replic

matrix list ser


*set scheme cleanplots 

coefplot (matrix(replic[,1]), se(ser[,1]) label("Aizer") bcolor(blue)) ///
         (matrix(replic[,2]), se(ser[,2]) label("Replication") bcolor(red)) /// 
		 (matrix(replic[,3]), se(ser[,3]) label("Replication-Emp") bcolor(green)), /// 
		 recast(bar) barwidth(0.2) ///
		 yscale(r(-2 2)) ///
		 ciopts(recast(rcap)) citop ///
		 vertical yline(0) ///
		 ytitle("Log DV") ///
		 xlabel(1 "Women Outside Option" 2 "Men Outside Option") ///
		 legend(position(6) rows(1)) ///
		 graphregion(color(white))
graph export "$result_folder/aizer_replication.pdf", replace  
